package com.cmc6.user.controller;

import com.cmc6.common.util.ApiResult;
import com.cmc6.user.model.dto.LoginByPhoneDTO;
import com.cmc6.user.model.dto.LoginByWxCodeDTO;
import com.cmc6.user.model.dto.LoginDTO;
import com.cmc6.user.model.dto.PhoneNotBlankDTO;
import com.cmc6.user.service.UserLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(tags = "用户登录")
@RequestMapping("/login")
@RestController
public class UserLoginController {

    @Resource
    UserLoginService baseService;

    @PostMapping
    @ApiOperation(value = "邮箱/手机号/用户自定义id 密码登录")
    public ApiResult<String> login(@RequestBody @Valid LoginDTO dto) {
        return ApiResult.ok("登录成功", baseService.login(dto));
    }

    @PostMapping(value = "/wxCode")
    @ApiOperation(value = "微信 code 登录/注册")
    public ApiResult<String> loginByWxCode(@RequestBody @Valid LoginByWxCodeDTO dto) {
        return ApiResult.ok("登录成功", baseService.loginByWxCode(dto));
    }

    @PostMapping(value = "/phone")
    @ApiOperation(value = "手机号 登录/注册")
    public ApiResult<String> loginByPhone(@RequestBody @Valid LoginByPhoneDTO dto) {
        return ApiResult.ok("登录成功", baseService.loginByPhone(dto));
    }

    @PostMapping(value = "/phone/sendCode")
    @ApiOperation(value = "手机号 登录 发送验证码")
    public ApiResult<String> loginByPhoneSendCode(@RequestBody @Valid PhoneNotBlankDTO dto) {
        return ApiResult.ok(baseService.loginByPhoneSendCode(dto));
    }

}
